package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private MemberDao memberDao;

    /**
     * 把运营统计需要的数据封装在map中返回页面,需要查询member,order表
     */
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        Map<String, Object> result = new HashMap<>();
        String today = DateUtils.parseDate2String(DateUtils.getToday());//reportDate
        //获取本周第一天的日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月第一天
        String thisMonthFirstDay = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //获取todayNewMember
        Integer todayNewMember = memberDao.findMemberCountByDate(today);

        Integer totalMember = memberDao.findMemberTotalCount();
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(thisWeekMonday);
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(thisMonthFirstDay);
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(thisWeekMonday);
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(thisWeekMonday);
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(thisMonthFirstDay);
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(thisMonthFirstDay);

        //热门套餐包含套餐名,预约本套餐的总人数,预约本套餐的总人数在所有预约客户的占比
        List<Map> hotSetmeal = orderDao.findHotSetmeal();
        result.put("reportDate",today);
        result.put("todayNewMember",todayNewMember);
        result.put("totalMember",totalMember);
        result.put("thisWeekNewMember",thisWeekNewMember);
        result.put("thisMonthNewMember",thisMonthNewMember);
        result.put("todayOrderNumber",todayOrderNumber);
        result.put("thisWeekOrderNumber",thisWeekOrderNumber);
        result.put("thisMonthOrderNumber",thisMonthOrderNumber);
        result.put("todayVisitsNumber",todayVisitsNumber);
        result.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        result.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        result.put("hotSetmeal",hotSetmeal);
        return result;
    }
}
